/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;


import cipher.CipherInputStream;
import cipher.CipherOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import packer.PackerOutputStream;
import packer.UnpackerInputStream;

/**
 *
 * @author Bartek
 */
public class Test {
    
    private final static Logger LOGGER = Logger.getLogger(Test.class.getName());
    
    public static void main(String[] args) throws Exception {

        FileInputStream in = new FileInputStream
                ("C:\\test.txt");

        PackerOutputStream packer = new PackerOutputStream(
                new CipherOutputStream(
                new FileOutputStream("C:\\packedAndEncrypted.txt")));

        byte[] buffer = new byte[4];
        int inputLength;
        while ((inputLength = in.read(buffer, 0, buffer.length)) != -1) {
            packer.write(buffer, 0, inputLength);
        }
        
        System.out.println("Pakowanie zakończone!");

        in.close();

        packer.close();
        
        
        FileOutputStream unpackedIn = new 
                FileOutputStream("C:\\unpackedAndDecrypted.txt");
        
        UnpackerInputStream unpacker = new UnpackerInputStream(
                new CipherInputStream(
                new FileInputStream("C:\\packedAndEncrypted.txt")));
        
        buffer = new byte[4];
        
        while ((inputLength = unpacker.read(buffer, 0, buffer.length)) != -1) {
            unpackedIn.write(buffer, 0, inputLength);
        }
        
        unpacker.close();
        
        unpackedIn.close();
        
        System.out.println("Rozpakowywanie zakończone!");
    }
}
